`
https://leetcode.cn/problems/detonate-the-maximum-bombs/
`

/**
 * @param {number[][]} bombs
 * @return {number}
 */
var maximumDetonation = function (bombs) {
  // 本题实际上等价于求一个有向图从哪个节点开始能遍历最多的节点
  const n = bombs.length
  const graph = Array.from({ length: n }, () => [])
  for (let i = 0; i < n; i++) {
    for (let j = 0; j < n; j++) {
      if (i === j) continue
      // 如果炸弹j在炸弹i的爆炸范围内，则i -> j
      if (Math.pow(bombs[i][0] - bombs[j][0], 2) + Math.pow(bombs[i][1] - bombs[j][1], 2) <= Math.pow(bombs[i][2], 2)) {
        graph[i].push(j)
      }
    }
  }

  let maxBomb = 0
  // 计算每个炸弹爆炸能炸掉多少个炸弹
  // 也就是从每个节点开始能遍历到多少个节点
  for (let i = 0; i < n; i++) {
    maxBomb = Math.max(maxBomb, bfs(graph, i))
  }
  return maxBomb
};

// 从 start 开始遍历图 graph，返回能遍历到的节点数
function bfs(graph, start) {
  let count = 0;
  const q = [start]
  const visited = Array(graph.length).fill(false)
  visited[start] = true
  while (q.length) {
    const node = q.shift()
    count++
    for (const neighbor of graph[node]) {
      if (!visited[neighbor]) {
        q.push(neighbor)
        visited[neighbor] = true
      }
    }
  }
  return count
}